//! 线程池配置模块
use serde::Deserialize;
use std::fs;

/// 线程池配置
#[derive(Debug, Deserialize, Clone)]
pub struct ThreadPoolConfig {
    pub pool_size: usize,
}

#[derive(Debug, Deserialize, Clone)]
pub struct TaskConfig {
    pub temp_directory: String,
}

/// 应用配置
#[derive(Debug, Deserialize, Clone)]
pub struct AppConfig {
    pub thread: ThreadPoolConfig,
    pub task: TaskConfig,
    pub ffmpeg_param: FfmpegConfig,
}

#[derive(Debug, Deserialize, Clone)]
pub struct FfmpegConfig {
    pub filename: String,
    pub segment_time: i8,
    pub thread_count: i8,
}

impl AppConfig {
    /// 从YAML文件加载配置
    pub fn from_file(path: &str) -> anyhow::Result<Self> {
        let config_content = fs::read_to_string(path)?;
        let config: AppConfig = serde_yaml::from_str(&config_content)?;
        Ok(config)
    }

    /// 创建默认配置
    pub fn default_config() -> Self {
        Self {
            thread: ThreadPoolConfig {
                pool_size: 20,
            },
            task: TaskConfig {
                temp_directory: String::from("C:\\mywork"),
            },
            ffmpeg_param: FfmpegConfig {
                filename: String::from("ffmpeg"),
                segment_time: 10,
                thread_count: 1,
            },
        }
    }
}
